﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using HalconDotNet;

namespace CarbonFiberDetection.ViewModel
{
    public class MainWindowViewModel:ViewModelBase
    {
        #region 成员
        private string _RunningAlready;
        private System.Timers.Timer posTimer;
        private DateTime StartTime;
        #endregion

        #region 属性
        public string RunningAlready
        {
            set { _RunningAlready = value; RaisePropertyChanged(); }
            get => _RunningAlready;
        }
        #endregion

        #region 函数
        public MainWindowViewModel() 
        {
            SystemInit();
        }

        /// <summary>
        /// 系统初始化
        /// </summary>
        public void SystemInit()
        {
            StartTime = DateTime.Now;
            posTimer = new System.Timers.Timer();
            posTimer.Elapsed += new System.Timers.ElapsedEventHandler(PosTimer_Tick);
            posTimer.Interval = 1 * 1000;
            posTimer.Start();


        }

        private void PosTimer_Tick(object sender, ElapsedEventArgs e)
        {
            var ts = DateTime.Now - StartTime;
            RunningAlready = $"{string.Format("{0:D2}",ts.Hours)}:{string.Format("{0:D2}", ts.Minutes)}:{string.Format("{0:D2}", ts.Seconds)}";
        }
        #endregion
    }
}
